package persistence.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import persistence.exceptions.RepositoryException;

public class ConnectionManager {

	public ConnectionManager getInstance() {
		return new ConnectionManager();
	}

	public void closeConnection(Connection conn) throws RepositoryException {
		try {
			conn.close();
		} catch (SQLException ex) {
			System.out.println("SQLException: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("VendorError: " + ex.getErrorCode());
			throw new RepositoryException("JDBC connection close error!", ex);
		}

	}

	public Connection getConnection() throws RepositoryException {
		Connection conn = null;
		try {
			conn = DriverManager
					.getConnection("jdbc:mysql://localhost/hazifeladat?"
							+ "user=user&password=useruser");
		} catch (SQLException | RepositoryException ex) {

			System.out.println("SQLException: " + ex.getMessage());
			throw new RepositoryException("JDBC connection error!", ex);
		}

		return conn;
	}

}
